package com.cloud.tsp.controller;

import com.cloud.api.domain.model.NoticeModel;
import com.cloud.core.util.R;
import com.cloud.api.domain.model.ModelName;
import com.cloud.api.domain.model.VehicleModel;
import com.cloud.api.domain.model.VehicleModelDto;
import com.cloud.api.validgroup.ValidateGroupInsert;
import com.cloud.api.validgroup.ValidateGroupUpdate;
import com.cloud.api.constants.StrVo;
import com.cloud.log.annotation.Log;
import com.cloud.log.enums.BusinessType;
import com.cloud.log.enums.OperatorType;
import com.cloud.tsp.service.IVehicleModelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author haohaibo
 * @since 2023-12-20
 */
@RestController
@RequestMapping("/vehicle-model")
public class VehicleModelController {

    @Resource
    private IVehicleModelService vehicleModelService;

    @Tag(name = "v1.0")
    @Operation(summary = "根据类型查询所有车型品牌（管理）")
    @PostMapping("/getModelBrand")
    @Log(title = "车型管理-根据类型查询所有车型品牌", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleModel> selectModelBrand(@RequestBody @Valid StrVo para){
        return R.ok(vehicleModelService.selectModelBrand(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据父级id查询子车型（管理）")
    @PostMapping("/getModelByParentId")
    @Log(title = "车型管理-根据父级id查询子车型", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleModel> selectModelByParentId(@RequestBody @Valid StrVo para){
        return R.ok(vehicleModelService.selectModelByParentId(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据车系查询车型列表图片（管理）")
    @PostMapping("/getUrlListById")
    @Log(title = "车型管理-根据车系查询车型列表图片", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleModel> selectUrlListById(@RequestParam String id ,@RequestParam String type) {
        return R.ok(vehicleModelService.selectUrlListById(id,type));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "获取车型树结构（管理）")
    @PostMapping("/getModelTreeList")
    @Log(title = "车型管理-获取车型树结构", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<VehicleModelDto> selectModelTreeList(){
        return R.ok(vehicleModelService.selectModelTreeList());
    }

    @Tag(name = "v1.0")
    @Operation(summary = "修改车型名称（管理）")
    @PostMapping("/updateModelName")
    @Log(title = "车型管理-修改车型名称", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE)
    public R updateModelName(@Validated(ValidateGroupUpdate.class) @RequestBody @Valid VehicleModel para){
        vehicleModelService.updateModelName(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "新增车型（管理）")
    @PostMapping("/insertModel")
    @Log(title = "车型管理-新增车型", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    public R insertModel(@Validated(ValidateGroupInsert.class) @RequestBody @Valid VehicleModel para){
        vehicleModelService.insertModel(para);
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "删除车型（管理）")
    @PostMapping("/deleteById")
    @Log(title = "车型管理-删除车型", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    public R deleteById(@RequestBody @Valid StrVo para){
        vehicleModelService.deleteById(para.getId());
        return R.ok();
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据子id查询父级名称（管理）")
    @PostMapping("/getParentNameById")
    @Log(title = "车型管理-根据子id查询父级名称", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<ModelName> selectParentNameById(@RequestBody @Valid StrVo para){
        return R.ok(vehicleModelService.selectParentNameById(para.getId()));
    }

    @Tag(name = "v1.0")
    @Operation(summary = "根据车型查询公告型号（管理）")
    @PostMapping("/getNoticeModelByModel")
    @Log(title = "车型管理-根据车型查询公告型号", businessType = BusinessType.OTHER, operatorType = OperatorType.MANAGE)
    public R<NoticeModel> selectNoticeModelByModel(@RequestParam("type") @Valid String type){
        return R.ok(vehicleModelService.selectNoticeModelByModel(type));
    }
}